<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%
	request.setAttribute("path", request.getContextPath());
%>
<script type="text/javascript">
$(function(){
	common.ajaxQuery("${root}/stock/rcv/list");
});
function check(needComment){

	var size = $("#dataList input[name='chkStock']:checked").size();
	if(size < 1){
		common.modalGlobalMessage("请选择需要你确认的的单据!");
		return false;
	}

	var result = true;
	if(needComment){
	$("#dataList input[name='chkStock']:checked").each(function(){
		var row = $(this).attr("row");
		var num = $("#unnormalNum"+row).val();
		if(common.isEmpty(num) || common.isNotInteger(num)){
			common.modalGlobalMessage("请填写>0的异常数量!");
			result = false;
			return false;
		}
		
	});
	}
	
	return result;
}
function selectAll(obj){
	$("#dataList input[name='chkStock']").prop("checked",$(obj).prop("checked"));
}
function getSelectedVal(){
	 var param = {};
	 var requestIdArr = new Array();
	 var unnormalNumArr = new Array();
	 var unnormalTypeArr = new Array();
	 var rcvCommentItemArr  = new Array();
	 
	$("#dataList input[name='chkStock']:checked").each(function(idx){

		var row = $(this).attr("row");
		requestIdArr[idx] = $(this).val();
		unnormalNumArr[idx] = $("#unnormalNum"+row).val();
		unnormalTypeArr[idx] = $("#unnormalType"+row).val();
		rcvCommentItemArr[idx] = $("#rcvCommentItem"+row).val();
	});
	param['requestId']=requestIdArr;
	param['unnormalNum']=unnormalNumArr;
	param['unnormalType']=unnormalTypeArr;
	param['rcvCommentItem']=rcvCommentItemArr;
	return $.param(param,true);
}
function doAction( type ,needComment){

	var uri = "${root}/stock/app/action/"+type;
	if(check(needComment)){
		common.ajaxSubmitWithData(uri,getSelectedVal(),"确认失败","",'common.ajaxQuery("${root}/stock/rcv/list")');
	}
}
</script>
<form class="form-horizontal" id="queryForm" role="form">
	<input name="orderName" value="" type="hidden">
	<input name="requestType" type="hidden" value="${param.requestType}">
    <table class="table table-hover">
		<tr>
			<th>申请人:</th>
			<td><input type="text" class="input-xlarge" name="requestUser" id="requestUser" value=""/></td>
			<th>申请日期:</th>
			<td colspan="3">
				<input type="text" data-date="${today}"  data-date-format="yyyy-mm-dd" class="input-medium datepicker" id="startDate" name="startDate" >
                  	&nbsp;&nbsp;~&nbsp;&nbsp;
               <input type="text" data-date="${today}"  data-date-format="yyyy-mm-dd" class="input-medium datepicker" id="endDate" name="endDate" >
			</td>
		</tr>
		<tr>
			<th>申请单号:</th>
			<td><input type="text" class="input-xlarge" name="manualId"/></td>
			<th>配件编码:</th>
			<td>
				<input type="text" class="input-xlarge" name="productPartId"/>
			</td>
			<th>配件名称:</th>
			<td>
				<input type="text" class="input-xlarge" name="productPartName"/>
			</td>
		</tr>
	</table>
	<div class="form-actions text-center">
		      <button type="button" class="btn btn-primary" onclick="common.ajaxQuery('${root}/stock/app/list')">查询</button>
		      <button type="button" class="btn btn-success" onclick="doAction('received',false)">全部收货</button>
		      <button type="button" class="btn btn-warning" onclick="doAction('other',true)">部分收货</button>
	 </div>
</form>
<table class="table table-striped table-bordered">
	<thead>
		<tr >
			<th class="text-center"><input type="checkbox" onclick="selectAll(this)"></th>
			<th class="span2 text-center">申请单号</th>
			<th class="span2 text-center">库存类型</th>
			<th class="span2 text-center">申请网点</th>
			<th class="span2 text-center">配件编码</th>
			<th class="span3 text-center">配件名称</th>
			<th class="span2 text-center">申请数量</th>
			<th class="span2 text-center">异常数量</th>
			<th class="span2 text-center">异常原因</th>
			<th class="span2 text-center">备注</th>
		</tr>
	</thead>
	<tbody id="dataList">
	</tbody>
</table>

